<?php

namespace cms\modules\v1\models\shop;
use cms\modules\v1\models\Common;
use common\models\Functions;
use yii\base\Exception;

/**
 * This is the model class for table "project_info".
 *
 * @property int $id
 * @property string $name
 */
class GoodsCategoryRelation extends \common\models\shop\GoodsCategoryRelation
{

    public function createRelation($category = [], $goodsId = 0) {
        if (empty($goodsId)) {
            throw new Exception('未知商品信息');
        }
        static::deleteAll(["goods_id" => $goodsId]);
        $isExist = [];
        $data['goods_id'] = $goodsId;
        if (!empty($category)) {
            foreach ($category as $v) {
                if (!in_array($v, $isExist)) {
                    $data['category_id'] = $v;
                    static::insertData($data);
                    $isExist[] = $v;
                }
            }
        }
    }
}
